//
//  DebtDetailsViewController.m
//  TenThousand
//
//  Created by 我的 on 16/6/24.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "DebtDetailsViewController.h"

@interface DebtDetailsViewController ()<UITextFieldDelegate>

@end

@implementation DebtDetailsViewController
{
    NSString    *phone;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"债权转让";
    [self createLeft:[UIImage imageNamed:@"ZHSZicon_03"] leftClick:^{
        [self.navigationController popViewControllerAnimated:YES];
    } right:nil rightClick:nil];
    
    [self createUI];
}
- (void)createUI {
    
    self.titleLabel.text = self.titleName;
    self.BenjinLB.text = self.BenjinStr;
    self.ShouyiLB.text = self.ShouyiStr;
    self.AllMoneyLB.text = self.AllStr;
    self.OutBenjinLB.delegate = self;
    self.OutShouyi.delegate = self;
    [self.Yanzheng addTarget:self action:@selector(yanzhengAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)yanzhengAction:(UIButton *)sender {
    NSString *loginName = [[NSUserDefaults standardUserDefaults]objectForKey:@"LoginName"];
    NSDictionary *dic = @{@"Tel":loginName,@"OrderType":@"2",@"OrderFrom":@"1"};
    
    [NetWorkManager requestWithType:HttpRequestTypePost withMethodName:@"Api.GetMsm" withParaments:dic withSuccessBlock:^(NSDictionary *object) {
        NSLog(@"%@",object);
        if ([object[@"Code"] isEqualToString:@"00000"]) {
            [ToastView showInfoWithStatus:@"操作成功"];
            phone = [NSString stringWithFormat:@"%@",object[@"Data"][0][@"VerificationCode"]];
        }else {
            [ToastView showInfoWithStatus:@"操作失败"];
        }
        
    } withFailureBlock:^(NSError *error) {
        
    } progress:nil];

    
}

-(void)textFieldDidEndEditing:(UITextField *)textField {
    float money = [self.OutBenjinLB.text floatValue]+[self.OutShouyi.text floatValue];
    self.OutSubMoney.text = [NSString stringWithFormat:@"%.2f",money];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    return [textField resignFirstResponder];
}

- (IBAction)sureBtn:(id)sender {
    if (![self.phoneNumber.text isEqualToString:phone]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入验证码" delegate: nil cancelButtonTitle:@"确定" otherButtonTitles: nil, nil];
        [alert show];
        return;
    }
    
      NSString *loginId = [[NSUserDefaults standardUserDefaults] objectForKey:@"LoginId"];
    
    NSLog(@"%.2f %.2f %.2f %.2f",[self.OutBenjinLB.text floatValue],[self.BenjinLB.text floatValue],[self.OutShouyi.text floatValue],[self.TransferableLix floatValue] );
    
    if (([self.OutBenjinLB.text floatValue] >= [self.BenjinLB.text floatValue]) || ([self.OutShouyi.text floatValue] >= [self.TransferableLix floatValue])) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"输入金额大于拥有金额" delegate: nil cancelButtonTitle:@"确定" otherButtonTitles: nil, nil];
        [alert show];
        return;
    }
      NSDictionary *para = @{
                           @"BorrowListId":self.BorrowListId,
                           @"Borrowid":self.Borrowid,
                           @"Detail":@"急需用钱",
                           @"Amount":self.OutBenjinLB.text,
                           @"TransfeLiXi":self.OutShouyi.text,
                           @"TransferableAmount":self.TransferableAmount,
                           @"TransferableLix":self.TransferableLix,
                           @"LoginId":loginId
                           };
    
    [NetWorkManager requestWithType:HttpRequestTypePost withMethodName:@"Transfer.GetAddTransfer" withParaments:para withSuccessBlock:^(NSDictionary *object) {
        NSLog(@"%@",object);
        if ([object[@"Code"] isEqualToString:@"00000"]) {
            [ToastView showInfoWithStatus:@"操作成功"];
        }else {
            [ToastView showInfoWithStatus:@"操作失败"];
        }
        
    } withFailureBlock:^(NSError *error) {
        
    } progress:nil];
}

@end
